package com.neu.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.neu.mapper.SupplierMapper;
import com.neu.po.Supplier;
import com.neu.po.SupplierExample;
import com.neu.po.SupplierExample.Criteria;

@Service
public class SupplierServiceImpl implements SupplierService {

	@Autowired
	private SupplierMapper supplierMapper;
	
	@Override
	public PageInfo<Supplier> getPage(int pageNum,int pageSize,String keyword) {
		SupplierExample example = new SupplierExample();
		
		Criteria c1 = example.createCriteria();
		
		c1.andLangnameLike("%"+keyword+"%");
		
		PageHelper.startPage(pageNum, pageSize);
		
		List<Supplier> list = supplierMapper.selectByExample(example);
		
		PageInfo<Supplier> pageInfo = new PageInfo<>(list);
		
		return pageInfo;
	}

	@Override
	public int insert(Supplier supplier) {
		// TODO Auto-generated method stub
		return supplierMapper.insert(supplier);
	}

	@Override
	public int update(Supplier supplier) {
		// TODO Auto-generated method stub
		return supplierMapper.updateByPrimaryKey(supplier);
	}

	@Override
	public int delete(int id) {
		// TODO Auto-generated method stub
		return supplierMapper.deleteByPrimaryKey(id);
	}

}
